package com.zyh.langchain4j.controller;

import com.zyh.langchain4j.aiservice.ConsultantService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import reactor.core.publisher.Flux;

/**
 * @Author zyh
 * @Date 2025/6/21 16:04
 */
@RestController
@RestControllerAdvice
public class chatController {
    private final ConsultantService consultantService;

    public chatController(ConsultantService consultantService) {
        this.consultantService = consultantService;
    }

    /**
     * 向量数据库--检索本地
     */
    @RequestMapping(value = "/vector/stream/chat", produces = "text/html;charset=utf-8")
    public Flux<String> vectorStreamChat(String memoryId, String message) {
        //message:用户输入的问题
        Flux<String> chat = consultantService.memoryIdStreamChat(memoryId, message);
        return chat;
    }

    /**
     * 会话记忆模式--隔离
     */
    @RequestMapping(value = "/memoryId/stream/chat", produces = "text/html;charset=utf-8")
    public Flux<String> memoryStreamChat(String memoryId, String message) {
        //message:用户输入的问题
        Flux<String> chat = consultantService.memoryIdStreamChat(memoryId, message);
        return chat;
    }

    /**
     * 会话记忆模式
     */
    @RequestMapping(value = "/memory/stream/chat", produces = "text/html;charset=utf-8")
    public Flux<String> memoryStreamChat(String message) {
        //message:用户输入的问题
        Flux<String> chat = consultantService.memoryStreamChat(message);
        return chat;
    }

    /**
     * 给ai设置角色：
     */
    @RequestMapping(value = "/sys/stream/chat", produces = "text/html;charset=utf-8")
    public Flux<String> sysStreamChat(String message) {
        //message:用户输入的问题
        Flux<String> chat = consultantService.sysStreamChat(message);
        return chat;
    }

    /**
     * 调用AiService用法---流式
     */
    @RequestMapping(value = "/chat", produces = "text/html;charset=utf-8")
    public Flux<String> aiStreamChat(String message) {
        //message:用户输入的问题
        Flux<String> chat = consultantService.streamChat(message);
        return chat;
    }
//    /**
//     * 调用AiService用法
//     */
//    @RequestMapping("/ai/chat")
//    public String aiChat(String message) {
//        //message:用户输入的问题
//        String chat = consultantService.chat(message);
//        return chat;
//    }

//    /**
//     * 日常用法
//     */
//    @RequestMapping("/chat")
//    public String chat(String message) {
//        //message:用户输入的问题
//        String chat = aiChatModel.chat(message);
//        return chat;
//    }

}
